package crack;

import fem2.AbstractStructuralCrackDemo;
import fem2.Constraint;
import fem2.MaterialModel;
import fem2.Mesh;
import fem2.MeshGenerator;
import fem2.MeshUtilities;
import fem2.Model;
import fem2.enu.State;
import fem2.material.StVenantKirchhoffMM;
import fem2.observer.StressObserver;
import fem2.observer.TimeStepObserver;
import fem2.pre_and_post.GidMeshGenerator;
import fem2.strategies.Strategy;

public abstract class AbstractPlaneStrainCompressionTestUsingSDAElement extends
		AbstractStructuralCrackDemo {

	public AbstractPlaneStrainCompressionTestUsingSDAElement() {
		projectDir = "/home/hbui/kratos_janosch";
		projectName = "compression-test.gid";
	}

	@Override
	public Mesh createMesh() {
		String fn = projectDir + '/' + projectName + '/' + meshFileName;
		MeshGenerator mg = new GidMeshGenerator(fn);
		Mesh mesh = mg.getMesh(2);
		return mesh;
	}

	@Override
	public Model createConditions(Model m) {
		Mesh mesh = m.getMesh();

		Constraint cx = new Constraint(false, true);
		Constraint cy = new Constraint(true, false);
		Constraint cuy = new Constraint(true, false);

		cuy.setValue(1, -10);

		MeshUtilities.seekNode(mesh, 0.0, 0.0).addConstraint(cx);
		mesh.addConstraint(cy, MeshUtilities.seekNodesOnSurface(mesh, 0.0, 1.0, 0.0));
		mesh.addConstraint(cuy, MeshUtilities.seekNodesOnSurface(mesh, 0.0, 1.0, -140.0));

		return m;
	}

	@Override
	public MaterialModel createMaterial(Model m) {
		double E = 20;
		double nu = 0.25;
		double t = 1.0;
		double rho = 0.0;
		State ss = State.PLANE_STRAIN;

		return new StVenantKirchhoffMM(E, nu, t, rho, ss);
	}

	@Override
	public void addObservers(final Model m, final Strategy s, TimeStepObserver o) {
		addFundamentalObservers(m, s, o);
		addObserversForCrackProblem(m, s, o);
		s.addObserver(new StressObserver(m));
	}

}
